#include <stdio.h>
#include <stdlib.h>  /* exit() 函数 */
#include <ctype.h>
#include <string.h>
void input ();
void output ();

 struct Books
{
    int a1;
    int a2;
    int a3;
    char sentence[810][20];
    double ave;
} book ;
int i =0;
int j =0;

FILE *pdf;

int main()
{ 
   pdf = fopen("stud.csv", "w");
   if(pdf == NULL)
   {
      printf("Error!");
      exit(1);
   }

   printf("please enter your data\n");
   printf("and press 'ctrl + z' to end your input:\n");
   input ();
   output(); 
  
   fclose(pdf);
 
   return 0;
}
void input()
{   
    char c;
    while((c=getchar())!=EOF){
        if(isdigit(c)){
            book.sentence[i][j++]=c;
        }
        else{
            i++;
            j=0;
            continue;
        }
    }
}
void output(){
    i--;
    for(int k=0;k<=i;k++){
        if(k%4==0){
            fprintf(pdf,"%s,",book.sentence[k]);
        }
        else if(k%4==1){
            book.a1=atoi(book.sentence[k++]);
            book.a2=atoi(book.sentence[k++]);
            book.a3=atoi(book.sentence[k]);
            book.ave=(book.a1+book.a2+book.a3)/3.0;
            fprintf(pdf,"%d,%d,%d,%.2llf\n",book.a1,book.a2,book.a3,book.ave);
        }
    }
}